﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <script src="https://cdn.bootcss.com/angular.js/1.7.0/angular.min.js"></script>
</head>
<!-- 不指定ng-Controller的写法，会报错:01Element.html:16 Uncaught TypeError: $scope.hello is not a function
    ng-controller=""的写法报错:angular.js:14996 Error: [$controller:ctrlfmt] http://errors.angularjs.org/1.7.0/$controller/ctrlfmt?p0=
<body ng-app="myApp" >
    <button type="button" onclick="sayHello()">Say Hello</button>
    <label>To</label>
    <input type="text" id="name" placeholder="Input a name." />
    <script type="text/javascript">
        function sayHello() {
            var $scope = angular.element(document).find("body").scope();
            $scope.hello();
        };
    </script>
    <script type="text/javascript">
        var app = angular.module("myApp", []);
        app.controller("", function ($scope) {
            $scope.hello = function () {
                //Uncaught Error: [jqLite:nosel] http://errors.angularjs.org/1.7.0/jqLite/nosel
                //angular.element("#name");

                //angular.element(document).find("#name") 无法找到值
                //angular.element(document).find("input:first") 无法找到值
                var name = angular.element(document).find("input").value;
                alert(["Hello", name].join());
            };
        });
    </script>
</body>
    -->
<body ng-app="myApp" ng-controller="1">
    <button type="button" onclick="sayHello()">Say Hello</button>
    <label>To</label>
    <input type="text" id="name" placeholder="Input a name." />
    <script type="text/javascript">
        function sayHello() {
            var $scope = angular.element(document).find("body").scope();
            $scope.hello();
        };
    </script>
    <script type="text/javascript">
        var app = angular.module("myApp", []);
        app.controller("1", function ($scope) {
            $scope.hello = function () {
                //Uncaught Error: [jqLite:nosel] http://errors.angularjs.org/1.7.0/jqLite/nosel
                //angular.element("#name");

                //angular.element(document).find("#name") 无法找到值
                //angular.element(document).find("input:first") 无法找到值
                //angular.element(document).find("input").value; 取到的值是undefined
                var name = angular.element(document).find("input").val();
                alert(["Hello,", name,"!"].join(""));
            };
        });
    </script>
</body>
</html>
